<template>
  <div class="main-content">
    <div class="main-header">
      <h2>地点信息</h2>
    </div>
    <div class="main-section">
      <div class="card">
        <ul>
          <!-- 使用新的样式类 -->
          <a v-for="location in locations" :key="location.name" class="location-item" @click="editLocation(location.name)">
            <h3><i class="fa fa-map-marker"></i> {{ location.name }}</h3>
          </a>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LocationsPage',
  data() {
    return {
      locations: []
    };
  },
  mounted() {
    this.fetchLocations();
  },
  methods: {
    fetchLocations() {
      //fetch('http://192.168.101.124:9002/ShowLocations')
      fetch('/ShowLocations')
        .then(response => response.json())
        .then(data => {
          this.locations = data;
        })
        .catch(error => {
          console.error('获取地点信息失败:', error);
        });
    },
    editLocation(name) {
      this.$router.push({ name: 'LocationEditPage', params: { name } });
    }
  }
};
</script>

<style scoped>
/* 主内容区域样式 */
.main-content {
  flex: 1;
  padding: 20px;
  max-width: 1200px; 
  margin: 0 auto; 
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.main-header h2 {
  font-size: 24px;
}

.main-section {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.card {
  background-color: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 20px;
  display: block; 
  text-align: left; 
  width: 100%;
  margin: 0 auto;
}

.card h3 {
  font-size: 18px;
  margin-bottom: 1px; /* 缩小行间距 */
}

/* 添加新的样式类 */
.location-item {
  display: flex;
  align-items: center;
}
.location-item i {
  margin-right: 8px;
}
</style>